<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加新闻</title>
    <link  href="../images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">

    <link rel="stylesheet" href="../css/messages_doctor_mes_add.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/sweetalert.css?cache=<%=Math.random()%>" >
    <link href="https://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/public.css?cache=<%=Math.random()%>">
    <script src="../js/jquery-1.9.1.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="../css/editor/summernote.css" rel="stylesheet">
    <script src="../css/editor/summernote.js"></script>
    </head>
<body>
    <%@ include file="../header.jsp"%>
    <!--内容-->
    <div class="containerone">
    <%@ include file="../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
    <!--右边内容-->
    <!--右边内容-->

          <div class="message_hos_news_container" id="add_content">
    <div class="add_doctor_tittle" v-html="option"></div>
              <div class="add_doctor">
                  <span>添加新闻</span>
                  <a href="javascript:void(0);"><button class="back_doctor_mes" @click="back()" >返回</button></a>
              </div>
              <%--编辑新闻开始--%>


                <%--编辑新闻开始--%>
                 <div class="news_eidt_title"><span>新闻标题:</span><input class="news_add_tittle" name="title"  type="text" v-model="title" required >
                   <%--<p class="news_title_tip">新闻标题不要超过50字</p>--%>
                    <div class="clearfix"></div>
                 </div>
                 <div class="news_eidt_title"><span>作者:</span><input class="news_add_author" name="author" type="text" v-model="author">
                  <%--<p class="news_author_tip">作者不要超过50字</p>--%>
                    <div class="clearfix"></div>
                 </div>
                 <div class='doc_good_at'>
                    <div class='doc_good_at_tip'><span>新闻简介:</span>(限输入200字符)</div>
                    <div class='doc_good_at_textarea'>
                       <textarea name="summary" id="" style="width:900px;height:150px;"  class="news_add_summary"  v-model="summary"></textarea>
                    </div>
                 </div>
    <p class="news_summary_tip"></p>
      <div class='doc_good_at'>
      <div class='doc_good_at_tip'><span>新闻内容:</span></div>
      <div class='doc_good_at_textarea'>
       <div style="width:900px;">
      <div id="editor"></div>
       </div>
      </div>
    <p class="news_content_tip"></p>
    <div class="add_doctor_cancel_sure">
    <button @click="cancel()" class="cancel_news_sure add_cancel">取消</button>
    <button @click="submit()" class="add_news_sure add_sure" >确定</button>
    </div>
    </div>
    <%--编辑新闻结束--%>
    <%--医生编辑取消和确定开始--%>

    <div class="clearfix"></div>

    <%--医生编辑取消和确定结束--%>
  </div>
</div>
</div>
</div>
<script src="../js/sweetalert-dev.js"></script>
  <script type="text/javascript">
    new Vue({
       el:'#add_content',
       data:{
         option:'',
         labelId:'',
         title:'',
         author:'',
         summary:'',
         content:'',
         titleExist:true,
         authorExist:false,
    },
    ready:function(){
    $(document).ready(function() {
    $('#editor').summernote({
        height:260,
        lang:'zh-CN',
    callbacks: {
    onImageUpload: function(files) {
    // upload image to server and create imgNode...
    var img = localImg(files[0]);
    }
    }
    });
    })
        function localImg(file) {
        var xmlhttprequest;
        var form = new FormData();
        form.append("file", file);
        if (window.XMLHttpRequest) {
        xmlhttprequest = new XMLHttpRequest();
        if (xmlhttprequest.overrideMimeType) {
        xmlhttprequest.overrideMimeType("text/xml");
        }
        }
        xmlhttprequest.open("POST", "http://cloud.eeesys.com/pu/upload.php", true);
        xmlhttprequest.onreadystatechange = callback.bind(this);
        xmlhttprequest.send(form);
        function callback() {
        if (xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200) {
        var res = JSON.parse(xmlhttprequest.responseText);
        if (res.errcode == 0) {
        $('#editor').summernote('insertImage', res.img);
        } else {
        swal({
        txt: decodeURI(res.errmsg),
        title: "",
        });
        }
        }
        }
        }
    <%--$('.news_title_tip,.news_author_tip,.news_summary_tip,.news_content_tip').hide()--%>
        var self = this;
        var add_content = getHrefParms("add_content");
        self.labelId = add_content.labelId;
        self.option = add_content.option;
       console.log(self)
      },
        methods:{
        submit:function(){
        var self = this;
        var news_title=self.title;
        var news_author=self.author
        if(news_title.trim()==""){
        swal('用户名不能为空')
        <%--$('.news_title_tip').text('用户名不能为空').show().delay(1000).hide(300);--%>
        return;
        }else if(news_title.length>50){
               swal('新闻标题不能超过50个字')
         }
         else if(news_author.trim()==""){
        $('.news_author_tip').show().delay(1000).hide(300);
        return;
        }else if(news_author.length>50){
            swal('作者不能超过50个字')
        }
       else{
      var sHTML = $('.note-editable').html();
         $.ajax({
            type: 'POST',
            url: "add_content.jsp",
            data: {
            act: "add_news",
            labelId:self.labelId,
            title:self.title,
            author:self.author,
            summary:self.summary,
            content:encodeURI(sHTML.replace(/"/g, "'")),
            },
            success: function(res) {
            console.log(res);
            res = JSON.parse(res);
            if (res.errcode == 0) {
            location.href="content.jsp";
            } else {
            swal(res.errmsg);
            }
            },
        });
        }
        },
    cancel:function(){
    location.href="content.jsp";
    },
    back:function(){
    location.href="content.jsp";
    }
        }
    })

</script>

</body>
</html>
